Skip to content

[numpy.md] Update np.random → Generator API#549

Open
Chihiro2000GitHub wants to merge 1 commit intomainfrom
update-rng-numpy
Open

[numpy.md] Update np.random → Generator API#549
Chihiro2000GitHub wants to merge 1 commit intomainfrom
update-rng-numpy

Conversation

@Chihiro2000GitHub
Copy link
Copy Markdown
Collaborator

Summary

This PR migrates legacy NumPy random API calls in numpy.md as part of QuantEcon/meta#299.
All np.random.randn, np.random.binomial, and from numpy.random import uniform usages are replaced with the Generator API via np.random.default_rng().

Details

  • rng = np.random.default_rng() is introduced at the first point of use (Mutability section) and reused throughout the main lecture text.
  • Exercise solution blocks (np_ex3, np_ex4) define their own local rng to remain self-contained.
  • np_ex4 (Part 1 and Part 2, exercise and solution) retains seed 123 via np.random.default_rng(123), matching the original intent of reproducible comparison between broadcasting and for-loop results.
  • DiscreteRV in the np_ex2 solution stores self.rng = np.random.default_rng() in __init__ and uses self.rng.uniform(...) in draw.
  • No fixed seed was introduced beyond what was already present in the original.
  • No Numba-related code was found in this file.
  • Local build completed successfully (jb build lectures); numpy.md executed without errors in 30 seconds.

Notes for reviewers

One item was intentionally left unchanged and would benefit from reviewer judgment:

The prose in the Sub-packages section currently reads:

We've already seen how we can generate random variables using np.random

After this migration, the code directly below uses rng.standard_normal() and rng.binomial() rather than np.random.xxx() directly. Technically rng is still obtained from np.random.default_rng(), so the sentence is not wrong — but it may feel slightly mismatched to a reader. Happy to update the wording if you think that would be clearer.

Hi @mmcky and @HumphreyYang, I'd be grateful if you could take a look when you have time.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 9, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant